home *** CD-ROM | disk | FTP | other *** search
-
- {sample for TDirTree; see dirtree.pas for details}
-
- unit main;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ComCtrls, dirtree, StdCtrls, FileCtrl, ExtCtrls,shellapi;
-
- type
- TForm1 = class(TForm)
- Panel1: TPanel;
- Image1: TImage;
- Panel2: TPanel;
- Label1: TLabel;
- CheckBox1: TCheckBox;
- DriveComboBox1: TDriveComboBox;
- GroupBox1: TGroupBox;
- CheckBox2: TCheckBox;
- CheckBox3: TCheckBox;
- CheckBox4: TCheckBox;
- CheckBox5: TCheckBox;
- CheckBox6: TCheckBox;
- CheckBox7: TCheckBox;
- Panel3: TPanel;
- ListView1: TListView;
- Panel4: TPanel;
- Panel5: TPanel;
- Button1: TButton;
- Button2: TButton;
- Label2: TLabel;
- Edit1: TEdit;
- Button3: TButton;
- procedure DirTree1AddDir(Filename: string; var DoAdd: Boolean);
- procedure DirTree1Change(Sender: TObject; Node: TTreeNode);
- procedure DriveComboBox1Change(Sender: TObject);
- procedure CheckBox1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure FormActivate(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Image1Click(Sender: TObject);
- procedure CheckBox2Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- procedure dragover(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
- procedure dragdrop(Sender, Source: TObject; X, Y: Integer);
- private
- { Private-Deklarationen }
- public
- { Public-Deklarationen }
- procedure reloadlistview; // read the files in the listview
- end;
-
- var
- Form1: TForm1;
- dirtree1 : tdirtree; // this is our tdirtree-component (here as an object)
- allowchange : boolean = true;
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.DirTree1AddDir(Filename: string; var DoAdd: Boolean);
- begin
- if checkbox1.checked then
- if upcase(filename[1]) <> upcase(drivecombobox1.drive) then doadd := false;
- // add only folders descending from the selected drive
- end;
-
- procedure TForm1.DirTree1Change(Sender: TObject; Node: TTreeNode);
- begin
- caption := Dirtree1.directory;
- allowchange := upcase (dirtree1.drive) = upcase(drivecombobox1.drive);
- drivecombobox1.drive := dirtree1.drive;
- reloadlistview;
- end;
-
- procedure TForm1.DriveComboBox1Change(Sender: TObject);
- begin
- if not allowchange then begin
- allowchange := true;
- exit;
- end;
- dirtree1.drive := drivecombobox1.drive;
- if checkbox1.checked then dirtree1.reload;
- // show directorys of a different drive
- end;
-
- procedure TForm1.CheckBox1Click(Sender: TObject);
- begin
- dirtree1.reload; // mode has changed (see onadddir) therefore re-read the items
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- dirtree1 := tdirtree.create(self);
- dirtree1.align := alleft;
- dirtree1.width := 200;
- dirtree1.onchange := dirtree1change;
- dirtree1.onadddir := dirtree1adddir;
- dirtree1.parent := self;
- dirtree1.ondragover := dragover;
- dirtree1.ondragdrop := dragdrop;
-
- // now set the listview's small icons to dirtree1's shellicons to display the shell-given
- // icons in the listview;
- listview1.smallimages := dirtree1.shellicons;
- end;
-
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- dirtree1.free;
- end;
-
- procedure TForm1.FormActivate(Sender: TObject);
- var c :char;
- begin
- c := drivecombobox1.drive;
- dirtree1.drive := c;
- end;
-
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- dirtree1.fullexpand;
- end;
-
- procedure TForm1.Image1Click(Sender: TObject);
- begin
- if ShellExecute(Application.Handle,PChar('open'),PChar('http://home.t-online.de/home/mirbir.st/'),PChar(''),nil,SW_NORMAL) < 33 then
- if ShellExecute(Application.Handle,PChar('open'),PChar('netscape.exe'),PChar('http://home.t-online.de/home/mirbir.st/'),nil,SW_NORMAL) < 32 then
- if ShellExecute(Application.Handle,PChar('open'),PChar('iexplore.exe'),PChar('http://home.t-online.de/home/mirbir.st/'),nil,SW_NORMAL) < 32 then
- showmessage ('Please visit me at : http://home.t-online.de/home/mirbir.st');
- end;
-
- procedure TForm1.CheckBox2Click(Sender: TObject);
- var ds : tdirtype;
- begin
- ds := [];
- if checkbox2.checked then ds:=ds+[dthidden];
- if checkbox3.checked then ds:=ds+[dtsystem];
- if checkbox4.checked then ds:=ds+[dtarchive];
- if checkbox5.checked then ds:=ds+[dtreadonly];
- if checkbox6.checked then ds:=ds+[dtnormal];
- if checkbox7.checked then ds:=ds+[dtall];
- dirtree1.dirtype := ds;
- end;
-
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- dirtree1.reload;
- reloadlistview;
- end;
- procedure tform1.reloadlistview; // read the files in the listview
- var srec : tsearchrec ; // record for findfirst/next
- sfi : tshfileinfo; // record-structure for shgetfileinfo
- res : integer;
- str,dir : string;
- begin
- with listview1 do begin
- // do not show the changes until all of them are done
- items.beginupdate;
- // clear all items
- items.clear;
- dir := dirtree1.directory;
- // if not a \ at the end, add it there
- if dir[length(dir)] <> '\' then dir:=dir+'\';
- // add the file-mask (*.* by default);
- str:=dir+edit1.text;
- // now begin with findfirst/next
- fillchar(srec,sizeof(tsearchrec),0); // fill the structure with zero-bytes (make it clean)
- res := findfirst(str,faanyfile-favolumeid-fadirectory,srec);
- // if res = 0 then a file has been found
- while res = 0 do begin
- // now get the displayname ( like the shell : with/without extension)
- // and the sysiconindex (this is the index of the file's associated icon in
- // the sytem's image list; and we have this list in dirtree1.shellicons and
- // therefore in the listview's smallimages, too (formcreate)
- fillchar(sfi,sizeof(tshfileinfo),0); // delete the rubbish
- // this api does the /\ described things
- shgetfileinfo(pchar(dir+srec.name) { the full file-name},0 {dwattributes (not used here)},
- sfi {contains the resulting info}, sizeof(tshfileinfo),
- shgfi_displayname {get the shell-displayed file-name} or
- shgfi_sysiconindex {what could it be ?});
- // and now add a new item with the resulting parameters to the listview
- with {listview1.}items.add do begin
- caption := sfi.szdisplayname; // the displayname-result in the sfi-struct
- imageindex := sfi.iicon; // the sysiconindex-result in sfi
- end;
- res := findnext(srec); // read next file and close loop;
- end;
- // at last show the changes
- items.endupdate;
- end;
- end;
-
- procedure TForm1.Button3Click(Sender: TObject);
- begin
- reloadlistview;
-
- end;
-
- // drag'n'drop-handling
- procedure tform1.dragover(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
- begin
- if sender = listview1 then accept := true;
- end;
-
- procedure tform1.dragdrop(Sender, Source: TObject; X, Y: Integer);
- begin
- showmessage('Dropped to : '+dirtree1.dropdirectory);
- end;
-
- end.
-